acsstartupContainerPort
index
/diska/acs_build/ACS/LGPL/CommonSoftware/acsstartup/src/acsstartupContainerPort.py

This script is designed to pick a free container port for ACS to run on using 
ALL the arguments passed to the container. If theres a free port to run under,
it prints that to standard out. If the script encounters some error, it exits
with status 1.
 
Parameters: too many to list. Run "acsstarupContainerPort -h" to see them all
 
Assumptions: None. This script should handle most errors graciously returning
with an error exit code.
 
TODO:
-

 
Modules
       
atexit
os
socket
subprocess

 
Functions
       
access(...)
access(path, mode) -> True if granted, False otherwise
 
Use the real uid/gid to test for access to a path.  Note that most
operations will use the effective uid/gid, therefore this routine can
be used in a suid/sgid environment to test if the invoking user has the
specified access to the path.  The mode argument can be F_OK to test
existence, or the inclusive-OR of R_OK, W_OK, and X_OK.
chdir(...)
chdir(path)
 
Change the current working directory to the specified path.
cleanUp()
#-----------------------------------------------------------------------------
#--Functions
coercePortNumber(port_number)
This helper function takes a port number which can be in string or integer
format and converts it to an integer. In the event of any failure, it 
returns None. Also, in the case that the port number is set to be an offset
from the ACS_INSTANCE, this method handles that as well.
 
Params: port_number port number. Can be absolute (i.e., "3075") or dynamic 
(i.e., "0"-"24").
 
Returns: the port number in integer format or None if there was some sort
of failure
exit(...)
exit([status])
 
Exit the interpreter by raising SystemExit(status).
If the status is omitted or None, it defaults to zero (i.e., success).
If the status is numeric, it will be used as the system exit status.
If it is another kind of object, it will be printed and the system
exit status will be one (i.e., failure).
fstat(...)
fstat(fd) -> stat result
 
Like stat(), but for an open file descriptor.
getContainerDict(portsFile)
Returns a dictionary where each key is the name of a container and the 
value is the absolute TCP port number it should use.
 
Params:
- portsFile A file which contains "someContainerName 1234" on each line 
where 1234 is a TCP port number.
 
Returns: a dictionary where each key is the name of a container and the 
value is the absolute TCP port number it should use
getExistingPort(cont_name, port_dict, host_dict)
If the port dictionary already has an entry stating that this container 
should be using some port, returns that port. If not, returns None.
getNextAvailablePort(host, ports_dict, hosts_dict, baseport)
Returns the next available port
getPortsFile(baseport)
Returns the file containing a list of containers and used ports
getcwd(...)
getcwd() -> path
 
Return a string representing the current working directory.
getpid(...)
getpid() -> pid
 
Return the current process id
link(...)
link(src, dst)
 
Create a hard link to a file.
main(prog_args)
portIsFree(ip_addr, tcp_port)
Simple helper function returns true if the TCP port, tcp_port, of the
host, ip_addr, is free to use.
portNumberAlreadyUsed(port_number, host, port_dict, host_dict)
Function returns 1 if the port number is already in use and false
 otherwise.
remove(...)
remove(path)
 
Remove a file (same as unlink(path)).
rename(...)
rename(old, new)
 
Rename a file or directory.
sleep(...)
sleep(seconds)
 
Delay execution for a given number of seconds.  The argument may be
a floating point number for subsecond precision.
system(...)
system(command) -> exit_status
 
Execute the command (a string) in a subshell.

 
Data
        BASESLEEPTIME = 127
F_OK = 0
R_OK = 4
W_OK = 2
X_OK = 1
__DEBUG__ = False
argv = ['/alma/ACS-9.0/Python/bin/pydoc', '-w', 'acsstartupContainerPort']
container_file = None
environ = {'CPPFLAGS': '-fcheck-new', 'VLTINC': '-I/alma/A...LOG': '/alma/ACS-9.0/ACSSW', 'PY_PACKAGES_L': ''}
stderr = <open file '<stderr>', mode 'w'>